class Solution(object):
    def sumOddLengthSubarrays(self, arr):
        n = len(arr)
        ans = 0
        for i in range(n):
            left_count = i - 0
            right_count = n - 1 - i
            even_left = left_count // 2 + 1
            odd_left = left_count + 1 - even_left
            even_right = right_count // 2 + 1
            odd_right = right_count + 1 - even_right
            ans += arr[i] * (even_left * even_right + odd_left * odd_right)
        return ans
